<html>
<div id="myheader">
<?php
error_reporting(E_ALL);
?>
</div>


<title>OSPMS</title>
<head>


</head>


<div id="mybody">


<?php

echo "<table style='border: solid 1px black;'>";
//echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th><th>Email</th><th>Reg date</th></tr>"; -

$servername = "localhost";
$username = "ospms";
$password = "ospms";
$dbname = "OSPMS";


class TableRows extends RecursiveIteratorIterator {
	function __construct($it) {
        parent::__construct($it, self::LEAVES_ONLY);
    }

    function current() {
//        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
    }

    function beginChildren() {
        echo "<tr>";
    }

    function endChildren() {
        echo "</tr>" . "\n";
    }
}


try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$select = $conn->query('SELECT * FROM user_uploaded_files');

$total_column = $select->columnCount();
//var_dump($total_column);

for ($counter = 0; $counter <= $total_column; $counter ++) {
    $meta = $select->getColumnMeta($counter);
    $column[] = $meta['name'];
}
//print_r($column);


	echo "<tr>". " ";
	echo "<td> FileNumber </td> " ;
	echo "<td> Folder </td> " ;
	echo "<td> Name </td> " ;
	echo "<td> Link </td> " ;
	echo "</tr>". " ";

    $stmt = $conn->prepare("SELECT file_id, folder_id, file_name, file_location FROM user_uploaded_files");
    $stmt->execute();
    $result2 = $stmt->setFetchMode(PDO::FETCH_ASSOC);
    $result2 = $stmt->fetchAll();
//    var_dump($result2);
    $my_count = count($result2);
    echo ' ';
//    print '\n';
//    print_r($my_count);
    for( $i=0; $i<count($result2); $i++ )
    {
    	$my_file_id = $result2[$i]['file_id'];
    	$my_folder_id = $result2[$i]['folder_id'];
    	$my_filename = $result2[$i]['file_name'];
    	$my_location = $result2[$i]['file_location'];

	echo "<tr>". " \n";
        echo "<td style='width:150px;border:1px solid black;'>"; 
    	print($my_file_id);
	echo "</td>";
        echo "<td style='width:150px;border:1px solid black;'>"; 
    	print($my_folder_id);
	echo "</td>";
        echo "<td style='width:150px;border:1px solid black;'>"; 
    	print($my_filename);
	echo "</td>";
        echo "<td style='width:150px;border:1px solid black;'>"; 
	echo '<a href="https://54.172.36.22/uploads/';
    	print(substr($my_location,16));
    	print($my_filename);
	echo '">';
    	print($my_filename);
	echo '</a>';
	echo "</td>";
        echo "</tr>" . "\n";
    }

//    $dsn = null;
    }
catch(PDOException $e)
    {
    echo "Error: " . $e->getMessage();
    }
$conn = null;
echo "</table>";
?> 

</div>
</div>


